-- EmuProcsi -- Sum of integers from 1 to N -- Recursive example --

LOAD R7, #20        -- N
CALL #3             -- Call recursive sum(R7) function
HALT                -- R7 should contain 1+...+N = 210 = 0xD2

LOAD R0, #0         -- Function sum(N), N in R7, returns sum result in R7
ADD R0, R7          -- Backup N in R0
SUB R0, #1          -- If N == 1
JEQ #12             --     Returns 1
PUSH R7             -- Save current N
SUB R7, #1
CALL #3             -- Recursive call sum(N-1)
POP R0              -- Load previous N
ADD R7, R0          -- N + sum(N-1)
RET                 -- Returns result
